from pages.base_page import BasePage


class TradePage(BasePage):
    trade_name = '//*[@resource-id="cool.dingstock.mobile:id/trading_product_name_tv"]'
    newest_trade_detail = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[2]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]'
    trade_content = '//*[@resource-id="cool.dingstock.mobile:id/trading_tv"]'
    trade_price = '//*[@resource-id="cool.dingstock.mobile:id/single_price_tv"]'
    first_trade_like = '//*[@resource-id="cool.dingstock.mobile:id/tv_post_raise"]'
    trade_collect = '//*[@resource-id="cool.dingstock.mobile:id/tv_collection"]'
    back_button = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_left_icon"]'
    third_trade_menu = '//*[@resource-id="cool.dingstock.mobile:id/post_header_overlay"]'
    third_trade_report = '//*[@resource-id="cool.dingstock.mobile:id/rv_post_action"]/android.widget.LinearLayout[3]'
    newest_trade_menu = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[2]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/androidx.appcompat.widget.LinearLayoutCompat[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]'
    newest_trade_delete = '//*[@resource-id="cool.dingstock.mobile:id/rv_post_action"]'
    delete_confirm = '//*[@resource-id="cool.dingstock.mobile:id/confirm_tv"]'
    first_trade_detail = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]'
    first_trade_comment = '//*[@resource-id="cool.dingstock.mobile:id/edit_hint_tv"]'
    first_trade_comment_input = '//*[@resource-id="cool.dingstock.mobile:id/comment_et"]'
    comment_choose_emoji = '//*[@resource-id="cool.dingstock.mobile:id/select_emoji_iv"]'
    emoji_element = '//*[@resource-id="cool.dingstock.mobile:id/emoji_rv"]/android.view.ViewGroup[5]'
    trade_comment_send = '//*[@resource-id="cool.dingstock.mobile:id/send_btn"]'
    first_trade_comment_num = '//*[@resource-id="cool.dingstock.mobile:id/tv_post_comment"]'
    first_trade_1comment_like = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]'
    first_trade_1comment_like_num = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.TextView[1]'
    first_trade_1comment_body = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]'
    comment_delete = '//*[@resource-id="cool.dingstock.mobile:id/rv_menu_action"]'
    copy_button = '//*[@resource-id="cool.dingstock.mobile:id/rv_menu_action"]/android.widget.LinearLayout[1]'
    report_button = '//*[@resource-id="cool.dingstock.mobile:id/rv_menu_action"]/android.widget.LinearLayout[2]'
    contact_author = '//*[@resource-id="cool.dingstock.mobile:id/contact_btn"]'
    trade_detail_author_name = '//*[@resource-id="cool.dingstock.mobile:id/group_item_dynamic_user_name_txt"]'
    contact_author_name = '//*[@resource-id="cool.dingstock.mobile:id/tool_bar_middle"]'
    comment_choose_image = '//*[@resource-id="cool.dingstock.mobile:id/select_pic_iv"]'
    all_album = '//*[@resource-id="cool.dingstock.mobile:id/tv_title"]'
    test_album = '//*[@text="tesr"]'
    first_image_xpath = '//*[@resource-id="cool.dingstock.mobile:id/mCheckBoxPanel"]/android.widget.CheckBox[1]'
    next_step_xpath = '//*[@resource-id="cool.dingstock.mobile:id/tv_rightBtn"]'
    first_comment_detail = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/androidx.recyclerview.widget.RecyclerView[1]'
    download_image_xpath = '//*[@resource-id="cool.dingstock.mobile:id/img_download"]'
    comment_iamge_xpath = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_content_img"]'
    level2_comment_like_button = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]'
    level2_comment_like_num = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_like_txt"]'
    level2_comment_body = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]'
    close_comment_detail = '//*[@resource-id="cool.dingstock.mobile:id/iv_close"]'
    second_comment_detail = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_subContent_recycler"]/android.widget.FrameLayout[1]'
    second_comment_level2_body = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]'
    trading_zone = '//*[@resource-id="cool.dingstock.mobile:id/hot_trading_layer"]'
    filter_button = '//*[@resource-id="cool.dingstock.mobile:id/filter_iv"]'
    new_filter = '//*[@text="全新无瑕"]'
    filter_confirm_button = '//*[@resource-id="cool.dingstock.mobile:id/confirm_button"]'
    filter_reset_button = '//*[@resource-id="cool.dingstock.mobile:id/reset_tv"]'
    close_filter_button = '//*[@resource-id="cool.dingstock.mobile:id/close_iv"]'
    join_topic = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_topic_detail_publish_fra"]'
    publish_back_button = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_left_icon"]'
    first_trade_tag = '//*[@resource-id="cool.dingstock.mobile:id/trading_tag_tv"]'
    trading_zone_back_button = '//*[@resource-id="cool.dingstock.mobile:id/iv_back"]'
    publish_trade_specification = '//*[@text="交易发布规范"]'
    
    def into_newest_trade_detail(self):
        """进入最新一条交易详情页"""
        self.click_xpath(self.newest_trade_detail)

    def get_first_trade_name(self):
        """获取交易的商品名称"""
        return self.get_xpath_text(self.trade_name)

    def get_trade_content(self):
        """获取交易的文本内容"""
        return self.get_xpath_text(self.trade_content)

    def get_trade_price(self):
        """获取交易的价格"""
        return self.get_xpath_text(self.trade_price)

    def like_trade(self):
        """点赞第一条交易"""
        self.click_xpath(self.first_trade_like)

    def get_first_trade_like_num(self):
        """获取第一条交易点赞数量"""
        return self.get_xpath_text(self.first_trade_like)

    def collect_trade(self):
        """点击交易收藏按钮"""
        self.click_xpath(self.trade_collect)

    def trade_detail_back(self):
        """交易详情页返回"""
        self.click_xpath(self.back_button)

    def click_third_trade_menu(self):
        """点击第三条交易的菜单按钮"""

    def report_third_trade(self):
        """举报第三条交易"""
        self.click_xpath(self.third_trade_menu)
        self.click_xpath(self.third_trade_report)

    def click_newest_trade_menu(self):
        """点击最新发布的...按钮"""
        self.click_xpath(self.newest_trade_menu)


    def click_delete(self):
        """点击删除按钮"""
        self.click_xpath(self.newest_trade_delete)


    def confirm_delete(self):
        """确认删除"""
        self.click_xpath(self.delete_confirm)

        
    def into_first_trade(self):
        """进入第一条交易详情页"""
        self.click_xpath(self.first_trade_detail)
        
    def get_first_trade_comment_num(self):
        """获取第一条动态评论数量"""
        return self.get_xpath_text(self.first_trade_comment_num)
    
    def comment_first_trade_1(self, text):
        """交易一级评论，携带emoji表情"""
        self.click_xpath(self.first_trade_comment)
        self.set_xpath_text(self.first_trade_comment_input, text)
        self.click_xpath(self.comment_choose_emoji)
        self.click_xpath(self.emoji_element)
        self.click_xpath(self.trade_comment_send)
        
    def like_first_trade_comment1(self):
        """点赞第一条一级评论"""
        self.click_xpath(self.first_trade_1comment_like)
        
    def is_like_num_exist(self):
        """点赞后是否显示点赞数量"""
        return self.is_xpath_exist(self.first_trade_1comment_like_num)
    
    def delete_first_trade_comment1(self):
        """删除一级动态评论"""
        self.long_press(self.first_trade_1comment_body)
        self.click_xpath(self.comment_delete)
        self.click_xpath(self.delete_confirm)
        
    def copy_comment_content(self):
        """复制评论内容"""
        self.long_press(self.first_trade_1comment_body)
        self.click_xpath(self.copy_button)
        
    def report_comment(self):
        """举报评论"""
        self.long_press(self.first_trade_1comment_body)
        self.click_xpath(self.report_button)
        
    def click_contact_author(self):
        """联系发布交易作者"""
        self.click_xpath(self.contact_author)
        
    def detail_author_name(self):
        """交易详情页发布者名称"""
        return self.get_xpath_text(self.trade_detail_author_name)
    
    def contact_autor_name(self):
        """联系发布者页面名称"""
        return self.get_xpath_text(self.contact_author_name)
    
    def trade_comment_level2(self, text):
        """交易二级评论，带图片"""
        self.click_xpath(self.first_trade_1comment_body)
        self.set_xpath_text(self.first_trade_comment_input, text)
        self.click_xpath(self.comment_choose_image)
        self.click_xpath(self.all_album)
        self.click_xpath(self.test_album)
        self.click_xpath(self.first_image_xpath)
        self.click_xpath(self.next_step_xpath)
        self.click_xpath(self.trade_comment_send)
        
    def look_comment_image(self):
        """查看交易二级评论图片"""
        self.click_xpath(self.first_comment_detail)
        self.click_xpath(self.comment_iamge_xpath)
        
    def is_download_image_exist(self):
        """下载图片按钮是否存在"""
        return self.is_xpath_exist(self.download_image_xpath)
    
    def into_first_comment_detail(self):
        """进入第一条评论详情页"""
        self.click_xpath(self.first_comment_detail)
        
    def like_level2_comment(self):
        """点赞第一个二级评论"""
        self.click_xpath(self.level2_comment_like_button)
        
    def is_level2_like_num_exist(self):
        """二级评论点赞数量是否显示"""
        return self.is_xpath_exist(self.level2_comment_like_num)
    
    def delete_level2_comment(self):
        """删除二级评论"""
        self.long_press(self.level2_comment_body)
        self.click_xpath(self.comment_delete)
        self.click_xpath(self.delete_confirm)
    
    def back_trade_detail(self):
        """返回交易详情"""
        self.click_xpath(self.close_comment_detail)
        
    def into_second_comment_detail(self):
        """第二条交易评论详情"""
        self.click_xpath(self.second_comment_detail)
        
    def copy_level2_comment(self):
        """复制二级评论"""
        self.long_press(self.second_comment_level2_body)
        self.click_xpath(self.copy_button)
    
    def report_level2_comment(self):
        """举报二级评论"""
        self.long_press(self.second_comment_level2_body)
        self.click_xpath(self.report_button)
    
    def into_trading_zone(self):
        """进入热门交易专区"""
        self.click_xpath(self.trading_zone)
        
    def filter_check_new(self):
        """交易专区点击筛选成色为全新"""
        self.click_xpath(self.filter_button)
        self.click_xpath(self.new_filter)
        self.click_xpath(self.filter_confirm_button)
        
    def reset_filter(self):
        """交易专区重置筛选条件"""
        self.click_xpath(self.filter_button)
        self.click_xpath(self.filter_reset_button)
        self.click_xpath(self.filter_confirm_button)
        
    def click_join_topic(self):
        """交易专区点击加入话题"""
        self.click_xpath(self.join_topic)
        return self.get_xpath_text(self.publish_trade_specification)
        
    def publish_go_back(self):
        """发布动态页面点击返回"""
        self.click_xpath(self.publish_back_button)
        
    def get_first_trade_tag(self):
        """获取筛选全新后的第一个交易的tag"""
        return self.get_xpath_text(self.first_trade_tag)
    
    def back_trade_page(self):
        """交易专区返回到交易首页"""
        self.click_xpath(self.trading_zone_back_button)